package com.shelpe.services.lexicon.entity.metrics;

import java.math.BigDecimal;

import lombok.Data;

@Data
public class InsightMetrics {

	private int impression;//展现量
	private int click;//点击量
	private int cost;//花费（分）
	private int directTransaction;//直接成交金额
	private int indirectTransaction;//间接成交金额
	private int directTransactionShipping;//直接成交笔数
	private int indirectTransactionShipping;//间接成交笔数
	private int favItemTotal;//宝贝收藏数
	private int favShopTotal;//店铺收藏数
	private int favTotal;//总收藏数
	private int transactionShippingTotal;//总成交笔数
	private int transactionTotal;//总成交金额
	private int competition;//竞争度
	private BigDecimal ctr = BigDecimal.ZERO;//点击率
	private BigDecimal cpc = BigDecimal.ZERO;//平均点击花费
	private BigDecimal roi = BigDecimal.ZERO;//投入产出比
	private BigDecimal coverage = BigDecimal.ZERO;//点击转化率
	
	
	public InsightMetrics add(InsightMetrics that){
		InsightMetrics metric = new InsightMetrics();
		metric.impression = this.impression + that.impression;
		metric.click = this.click + that.click;
		metric.cost = this.cost + that.cost;
		metric.directTransaction = this.directTransaction + that.directTransaction;
		metric.indirectTransaction = this.indirectTransaction + that.indirectTransaction;
		metric.directTransactionShipping = this.directTransactionShipping + that.directTransactionShipping;
		metric.indirectTransactionShipping = this.indirectTransactionShipping + that.indirectTransactionShipping;
		metric.favItemTotal = this.favItemTotal + that.favItemTotal;
		metric.favShopTotal = this.favShopTotal + that.favShopTotal;
		metric.favTotal = this.favTotal + that.favTotal;
		metric.transactionShippingTotal = this.transactionShippingTotal + that.transactionShippingTotal;
		metric.transactionTotal = this.transactionTotal + that.transactionTotal;
		
		metric.competition = (this.competition + that.competition) / 2;
		metric.ctr = this.ctr.add(that.ctr).divide(BigDecimal.valueOf(2));
		metric.cpc = this.cpc.add(that.cpc).divide(BigDecimal.valueOf(2));
		metric.roi = this.roi.add(that.roi).divide(BigDecimal.valueOf(2));
		metric.coverage = this.coverage.add(that.coverage).divide(BigDecimal.valueOf(2));
		return metric;
	}
	
	public final static InsightMetrics BLANK_INSIGHT_METRIC = new InsightMetrics();
	static{
		BLANK_INSIGHT_METRIC.cpc = BigDecimal.ZERO;
		BLANK_INSIGHT_METRIC.roi =  BigDecimal.ZERO;
		BLANK_INSIGHT_METRIC.coverage = BigDecimal.ZERO;	
	}
}

